package com.crl.manager.scene
{
	import com.crl.manager.state.StateMachine;
	
	import flash.display.DisplayObjectContainer;
	
	public class SceneManager extends StateMachine
	{
		private var container:DisplayObjectContainer;
		
		private var currentScene:AbstractScene;
		public function SceneManager()
		{
			super();
		}
		
		
		public function setContainer(value:DisplayObjectContainer):void{
			container=value;
		}
		
		override public function set state(key:String):void{
			if(currentScene){
				currentScene.exit();
				container.removeChild(currentScene);
			}
			currentScene=get(key) as AbstractScene;
			if(currentScene){
				container.addChild(currentScene);
				if(currentScene.initialized==false){
					currentScene.initialize()
				}
				currentScene.enter();
			}
		}
	}
}